home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / UPC12BS1.ZIP / UUCP / UUCP.C next >
C/C++ Source or Header  |  1993-10-03  |  27KB  |  672 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    u u c p . c                                                     */
  3. /*                                                                    */
  4. /*    UUCP lookalike for IBM PC.                                      */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*    Changes Copyright (c) 1989-1993 by Kendra Electronic            */
  9. /*    Wonderworks.                                                    */
  10. /*                                                                    */
  11. /*    All rights reserved except those explicitly granted by the      */
  12. /*    UUPC/extended license agreement.                                */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: uucp.c 1.9 1993/10/03 20:43:08 ahd Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: uucp.c $
  24.  * Revision 1.9  1993/10/03  20:43:08  ahd
  25.  * Normalize comments to C++ double slash
  26.  *
  27.  * Revision 1.8  1993/10/02  19:07:49  ahd
  28.  * Use 0644 permissions on files
  29.  *
  30.  * Revision 1.7  1993/09/20  04:48:25  ahd
  31.  * TCP/IP support from Dave Watt
  32.  * 't' protocol support
  33.  * OS/2 2.x support (BC++ 1.0 for OS/2)
  34.  *
  35.  * Revision 1.6  1993/08/02  03:24:59  ahd
  36.  * Further changes in support of Robert Denny's Windows 3.x support
  37.  *
  38.  * Revision 1.5  1993/07/31  16:27:49  ahd
  39.  * Changes in support of Robert Denny's Windows support
  40.  *
  41.  * Revision 1.4  1993/04/11  00:35:46  ahd
  42.  * Global edits for year, TEXT, etc.
  43.  *
  44.  * Revision 1.3  1993/04/05  04:35:40  ahd
  45.  * Use timestamp/file size information returned by directory search
  46.  *
  47.  * Revision 1.2  1992/12/11  12:45:11  ahd
  48.  * Normalize paths for files read
  49.  *
  50.  */
  51.  
  52. /*--------------------------------------------------------------------*/
  53. /*                                                                    */
  54. /*    Change history:                                                 */
  55. /*                                                                    */
  56. /*       02/08/81 H.A.E.Broomhall                                     */
  57. /*                Hacked for UUPC/extended 1.09c                      */
  58. /*       04/27/91 Drew Derbyshire                                     */
  59. /*                Modified for UUPC/extended 1.10a                    */
  60. /*       09/26/91 Mitch Mitchell                                      */
  61. /*                Support for UUX                                     */
  62. /*       01/26/92 Drew Derbyshire                                     */
  63. /*                Various comment and error message clean up          */
  64. /*--------------------------------------------------------------------*/
  65.  
  66. /*--------------------------------------------------------------------*/
  67. /*                        system include files                        */
  68. /*--------------------------------------------------------------------*/
  69.  
  70. #include  <ctype.h>
  71. #include  <direct.h>
  72. #include  <fcntl.h>
  73. #include  <io.h>
  74. #include  <stdio.h>
  75. #include  <stdlib.h>
  76. #include  <string.h>
  77. #include  <sys/types.h>
  78. #include  <sys/stat.h>
  79.  
  80. #ifdef _Windows
  81. #include <windows.h>
  82. #endif
  83.  
  84. /*--------------------------------------------------------------------*/
  85. /*                    UUPC/extended include files                     */
  86. /*--------------------------------------------------------------------*/
  87.  
  88. #include  "lib.h"
  89. #include  "expath.h"
  90. #include  "getopt.h"
  91. #include  "getseq.h"
  92. #include  "hlib.h"
  93. #include  "hostable.h"
  94. #include  "import.h"
  95. #include  "uundir.h"
  96. #include  "security.h"
  97. #include  "timestmp.h"
  98. #include  "execute.h"
  99.  
  100. #ifdef _Windows
  101. #include "winutil.h"
  102. #include "logger.h"
  103. #endif
  104.  
  105. /*--------------------------------------------------------------------*/
  106. /*                          Global variables                          */
  107. /*--------------------------------------------------------------------*/
  108.  
  109. static boolean       spool_flag = FALSE;
  110. static char          spool_file[FILENAME_MAX]; // alt spool file name
  111. static boolean       dir_flag = TRUE;
  112. static boolean       xeqt_flag = TRUE;    // Triggered by -r option
  113. static char          grade = 'n';         // Default grade of service
  114. static boolean       mail_me = FALSE;     // changes with -m
  115. static boolean       mail_them = FALSE;   // changes with -n
  116. static char  remote_user[10];             // user to mail with -n
  117. static char  *destn_file;
  118. static char  flags[16];
  119.  
  120. currentfile();
  121.  
  122. /*--------------------------------------------------------------------*/
  123. /*    u s a g e                                                       */
  124. /*                                                                    */
  125. /*    Report flags used by program                                    */
  126. /*--------------------------------------------------------------------*/
  127.  
  128. static         void    usage(void)
  129. {
  130.       fprintf(stderr, "Usage: uucp\t[-c|-C] [-d|-f] [-gGRADE] [-j] [-m] [-nUSER] [-r] [-sFILE]\\\n\
  131. \t\t[-xDEBUG_LEVEL] source-files destination-file\n");
  132. }
  133.  
  134. /*--------------------------------------------------------------------*/
  135. /*    c p                                                             */
  136. /*                                                                    */
  137. /*    Copy a file                                                     */
  138. /*--------------------------------------------------------------------*/
  139.  
  140. static int cp(char *from, char *to)
  141. {
  142.       int         fd_from, fd_to;
  143.       int         nr, nw = -1;
  144.       char        buf[BUFSIZ*4]; // faster if we alloc a big buffer
  145.  
  146.       if ((fd_from = open(from, O_RDONLY | O_BINARY)) == -1)
  147.          return(1);        // failed
  148.       /* what if the to is a directory? */
  149.       /* possible with local source & dest uucp */
  150.       if ((fd_to = open(to, O_CREAT | O_BINARY | O_WRONLY, S_IWRITE | S_IREAD)) == -1) {
  151.          close(fd_from);
  152.          return(1);        // failed
  153.          /* NOTE - this assumes all the required directories exist!  */
  154.       }
  155.       while  ((nr = read(fd_from, buf, sizeof buf)) > 0 &&
  156.          (nw = write(fd_to, buf, nr)) == nr)
  157.          ;
  158.       close(fd_to);
  159.       close(fd_from);
  160.       if (nr != 0 || nw == -1)
  161.          return(1);        // failed in copy
  162.       return(0);
  163. } /* cp */
  164.  
  165. /*--------------------------------------------------------------------*/
  166. /*    s p l i t _ p a t h                                             */
  167. /*                                                                    */
  168. /*    split_path splits a path into 3 components.                     */
  169. /*    1)  The system next in line                                     */
  170. /*    2)  Any intermediate systems as a bang path                     */
  171. /*    3)  The actual file name/path                                   */
  172. /*                                                                    */
  173. /*    It tries to be a little clever with idiots, in recognizing      */
  174. /*    system=this machine                                             */
  175. /*--------------------------------------------------------------------*/
  176.  
  177. static         void    split_path(char *path,
  178.                                   char *system,
  179.                                   char *inter,
  180.                                   char *file)
  181. {
  182.       char    *p_left, *p_right, *p;
  183.  
  184.       *system = *inter = *file = '\0';    // init to nothing
  185.       for (p = path;; p = p_left + 1)  {
  186.          p_left = strchr(p, '!');         // look for the first bang
  187.          if (p_left == NULL)  {           // not a remote path
  188.             strcpy(file, p);              // so just return filename
  189.             return;
  190.          }
  191.          /* now check if the system was in fact us.
  192.        If so strip it and restart */
  193.          if (equaln(E_nodename, p, p_left - p) &&
  194.             (E_nod